package com.hyx.spring.config;

import com.hyx.spring.bean.Animal;
import com.hyx.spring.bean.Cat;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

/**
 * @Author hyx
 * @Description 将Animal通过@Bean注解的方式注册到Spring容器
 *         @Scope("prototype") 将animal多实例之后
 * @Date 2024/3/10 21:13
 * @Version 1.0
 */
@Configuration
@ComponentScan("com.hyx.spring.bean")
public class AnimalConfig {

    @Scope("prototype")
    @Bean("animal")
    public Animal animal(){
        return  new Animal();
    }

    @Bean(initMethod = "init",destroyMethod = "destroy")
    public Cat cat(){
        return new Cat();
    }

}
